package com.systop.ltbook.webapp.catalog;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.systop.cms.catalog.service.CatalogManager;
import com.systop.cms.model.Catalogs;
import com.systop.cms.webview.service.CatalogFreeMarkerManager;
import com.systop.core.webapp.struts2.action.DefaultCrudAction;

@SuppressWarnings({ "serial"})
@Controller
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class LtCatalogAction extends DefaultCrudAction<Catalogs, CatalogManager> {

	private String path;
	
	@Autowired
	private CatalogFreeMarkerManager cataMgr;
	
	//栏目页面需要显示的夏季栏目列表
	private List<Catalogs> subs;

	/**
	 * 查看栏目
	 * @return
	 */
	public String catalog() {
		//根据访问路径查询栏目
		setModel(getModelByPath(path));
		//查询需要显示的子栏目...getId可能为null
		if (getModel()!= null){
			subs = cataMgr.getSubCatsById(getModel().getId());
		}
		return "catalog";
	}
	
	private Catalogs getModelByPath(String path){
		String hql = "from Catalogs c where c.rootPath = ?";
		return getManager().findObject(hql, path);
	}
	
	public List<Catalogs> getSubs() {
		return subs;
	}

	public void setPath(String path) {
		this.path = path;
	}
}
